<?php
	$orderid = $this->getRequest()->getParam('orderid');
	$order = Mage::getModel('sales/order')->loadByIncrementId($orderid);
?>

<script type="text/javascript">
function setCountryCode(obj){
	var t = document.getElementById("telcode"); 
	var tvalue = t.options[t.selectedIndex].value;
	document.getElementById("qiwiCountryCode").value=tvalue;
}

function changeStatus(val){
	if(val == 'qiwi'){
		document.getElementById("qiwiCountryTitle").style.display="block";
	}else{
		document.getElementById("qiwiCountryTitle").style.display="none";
	}
	
}

function IsChecked(val) {
	document.getElementById('messagetext').innerHTML = '';
	changeStatus(val);
	var radioWrap = document.getElementById("radio_wrap");
	li = radioWrap.getElementsByTagName("li");
	for(var i = 0; i < li.length; i++){
		li[i].className = "";
	}
	document.getElementById(val).className = "checked";
	var obj = document.getElementById(val);
	obj.getElementsByTagName('input')[0].checked = true;
}

function checkFrom(){
	document.getElementById('messagetext').innerHTML = '';
	// 校验是否选中支付方式
	var checkRadioChecked = document.getElementsByName('method');
	for(var i=0;i<checkRadioChecked.length;i++){
		if(checkRadioChecked[i].checked){
			return true;
		}
	}
	document.getElementById('messagetext').innerHTML = '* This is a required field.';
	return false;
}
</script>

<div class="repayment_title">
	<h3><?php echo $this->__('Choose Payment Method')?></h3>
</div>
<div id="radio_wrap" class="clearfix">
<div id="messagetext"></div>
<form action="<?php echo $this->getBaseUrl();?>orderrepayment/repayment/redirect" method="post">
	<input type="hidden" name="orderid" value="<?php echo $orderid; ?>" />
	<ul class="clearfix">
		
		<li onclick="IsChecked('yandex');" id="yandex">
			<div>
			<input type="radio" name="method" value="yandex_payment" style="display:none;" />
			<img src="<?php echo $this->getSkinUrl('images/custom/payment_yandex.jpg')?>" alt="yandex"/>
			<i></i>
			</div>
		</li>
		<li onclick="IsChecked('qiwi');" id="qiwi">
			<div>
			<input type="radio" name="method"  value="qiwi_payment" style="display:none;" />
			<img src="<?php echo $this->getSkinUrl('images/custom/payment_qiwi.jpg')?>" alt="qiwi"/>
			<i></i>
			</div>
		</li>
		<li onclick="IsChecked('creditcard');" id="creditcard">
			<div>
			<input type="radio" name="method" value="creditcard_payment" style="display:none;" />
			<img src="<?php echo $this->getSkinUrl('images/custom/payment_creditcard.jpg')?>" alt="master"/>
			<i></i>
			</div>
		</li>
	</ul>
	<div class="qiwiCountryAndUser">
	<div style="display:none;" id="qiwiCountryTitle">
		<div>
			<label><span style="color:red;font-size:1.5em;">*</span> <?php echo $this->__('ContryCode')?>:</label>
			<select name="telcode" id="telcode" onchange="setCountryCode();">
	                <option value="7"><?php echo $this->__('Russian Federation')?></option>
					<option value="9955"><?php echo $this->__('Georgia')?></option>
					<option value="507"><?php echo $this->__('Panama')?></option>
					<option value="44"><?php echo $this->__('Great Britain')?></option>
					<option value="992"><?php echo $this->__('Tajikistan')?></option>
					<option value="370"><?php echo $this->__('Lithuania')?></option>
					<option value="972"><?php echo $this->__('Israel')?></option>
					<option value="996"><?php echo $this->__('Kyrgyzstan')?></option>
					<option value="380"><?php echo $this->__('Ukraine')?></option>
					<option value="84"><?php echo $this->__('Vietnam')?></option>
					<option value="90"><?php echo $this->__('Turkey')?></option>
					<option value="994"><?php echo $this->__('Azerbaijan')?></option>
					<option value="374"><?php echo $this->__('Armenia')?></option>
					<option value="371"><?php echo $this->__('Latvia')?></option>
					<option value="91"><?php echo $this->__('India')?></option>
					<option value="66"><?php echo $this->__('Thailand')?></option>
					<option value="373"><?php echo $this->__('Moldova')?></option>
					<option value="1"><?php echo $this->__('United States')?></option>
					<option value="81"><?php echo $this->__('Japan')?></option>
					<option value="998"><?php echo $this->__('Uzbekistan')?></option>
					<option value="77"><?php echo $this->__('Kazakhstan')?></option>
	              </select> 
			<input name="qiwiCountryCode" id="qiwiCountryCode" type="text" value="7" readonly="readonly" size="5">
		</div>
		<div>
			<label><span style="color:red;font-size:1.5em;">*</span> <?php echo $this->__('Username')?>:</label><input name="qiwiUsername" id="qiwiUsername" type="text" size="20" maxlength="12">
		</div>
	</div>
	</div>
	<div class="repayment_submit">
		<div><?php echo '$'.sprintf("%01.2f",$order->getBaseGrandTotal()); ?></div>
		<input type="submit" class="submit" value="<?php echo $this->__('Check Out')?>" onclick="return checkFrom();" />
	</div>
</form>
</div>

